//
//  XLSubmitUserInfoView.m
//  XiangLove
//
//  Created by 宋振 on 2018/8/7.
//  Copyright © 2018年 BAOMIHUA.COM. All rights reserved.
//

#define kSpace                          10
#define kLeft                           15
#define kRight                          15

#import "XLSubmitUserInfoView.h"

#import "XLPersonCenterTool.h"

@interface XLSubmitUserInfoView ()

//提示第一条
@property (nonatomic, strong) UILabel *  titleOne;

//提示第二条
@property (nonatomic, strong) UILabel *  titleTwo;

//提示第三条
@property (nonatomic, strong) UILabel *  titleThree;

@end

@implementation XLSubmitUserInfoView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    
    if (self) {
        
        self.backgroundColor = RGBA(0, 0, 0, 0.4);
        
        /**
         设置界面显示
         */
        
        [self setCustomeView];
    }
    
    return self;
}


#pragma mark    - - - 设置界面显示 - - -

- (void)setCustomeView
{
    //设置背景显示
    UIView *bgView = [[UIView alloc] init];
    
    bgView.layer.cornerRadius = kScale(5);
    bgView.layer.masksToBounds = YES;
    bgView.backgroundColor = [UIColor whiteColor];
    
    [self addSubview:bgView];
    
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.mas_centerY);
        make.left.equalTo(self.mas_left).offset(kScale(53));
        make.right.equalTo(self.mas_right).offset(-kScale(52));
        make.height.mas_equalTo(211);
    }];
    
    //标题显示
    UILabel *titileLbl = [[UILabel alloc] init];
    titileLbl.textAlignment = NSTextAlignmentCenter;
    titileLbl.attributedText = [[NSMutableAttributedString alloc] initWithString:@"提高审核通过率" attributes:@{NSKernAttributeName:@1,NSFontAttributeName:[UIFont fontWithName:KFontNamePFMedium size:18],NSForegroundColorAttributeName:RGB(3, 3, 3)}];
    [bgView addSubview:titileLbl];
    
    [titileLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(bgView.mas_centerX);
        make.top.equalTo(bgView.mas_top).offset(20);
    }];
    
    //删除弹窗
    UIButton *deleteAlert = [UIButton buttonWithType:(UIButtonTypeCustom)];
    deleteAlert.frame = CGRectMake(0, 0, 12, 12);
    [deleteAlert setTitle:@"×" forState:(UIControlStateNormal)];
    [deleteAlert setTitleColor:RGB(153, 153, 153) forState:(UIControlStateNormal)];
    [deleteAlert addTarget:self action:@selector(deleteAlertAction:) forControlEvents:(UIControlEventTouchUpInside)];
    [bgView addSubview:deleteAlert];
    
    [deleteAlert mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(bgView).offset(-kScale(11));
        make.top.equalTo(bgView).offset(11);
        make.width.height.mas_equalTo(15);
    }];
    
    UIStackView *labelStack = [[UIStackView alloc] init];
    
    //竖向排列
    labelStack.axis = UILayoutConstraintAxisVertical;
    
    //充满
    labelStack.distribution = UIStackViewAlignmentFill;
    
    [bgView addSubview:labelStack];
    
    [labelStack mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(bgView.mas_top).offset(57);
        make.left.equalTo(bgView.mas_left).offset(kScale(kLeft));
        make.right.equalTo(bgView.mas_right).offset(kScale(kRight));
        make.height.mas_equalTo(84);
    }];
    
    [labelStack addArrangedSubview:self.titleOne];
    [labelStack addArrangedSubview:self.titleTwo];
    [labelStack addArrangedSubview:self.titleThree];
    
    
    //分割线
    UIView *lineHorizontal = [[UIView alloc] init];
    
    lineHorizontal.backgroundColor = RGB(238, 238, 238);
    
    [bgView addSubview:lineHorizontal];
    
    [bgView addSubview:lineHorizontal];
    
    [lineHorizontal mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(labelStack.mas_bottom).offset(15);
        make.left.right.equalTo(bgView);
        make.height.mas_equalTo(0.5);
    }];
    
    
    //按钮排放
    UIStackView *stackView = [[UIStackView alloc] init];
    
    stackView.backgroundColor = [UIColor lightGrayColor];
    
    //横向排放
    stackView.axis = UILayoutConstraintAxisHorizontal;
    
    //设置视图充满修饰
    stackView.distribution = UIStackViewDistributionFillEqually;
    
    [bgView addSubview:stackView];
    
    [stackView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(bgView);
        make.top.equalTo(lineHorizontal);
        make.bottom.equalTo(bgView.mas_bottom).offset(-5);
    }];
    
    //直接申请
    UIButton *leftButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
    [leftButton setAttributedTitle:[[NSAttributedString alloc] initWithString:@"直接申请" attributes:@{NSKernAttributeName:@1,
                                                                                                          NSFontAttributeName:[UIFont fontWithName:KFontNamePFMedium size:kScale(16)],
                                                                                                          NSForegroundColorAttributeName:RGB(102, 102, 102)
                                                                                                          }] forState:(UIControlStateNormal)];
    [leftButton addTarget:self action:@selector(directApplication:) forControlEvents:(UIControlEventTouchUpInside)];
    [stackView addArrangedSubview:leftButton];
    
    //提高之后申请
    UIButton *rightButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
    
    [rightButton setAttributedTitle:[[NSAttributedString alloc] initWithString:@"马上提高" attributes:@{NSKernAttributeName:@1,
                                                                                                          NSFontAttributeName:[UIFont fontWithName:KFontNamePFMedium size:kScale(16)],
                                                                                                          NSForegroundColorAttributeName:RGB(255, 187, 1)
                                                                                                          }] forState:(UIControlStateNormal)];
    [rightButton addTarget:self action:@selector(atOnceTimeApplication:) forControlEvents:(UIControlEventTouchUpInside)];
    [stackView addArrangedSubview:rightButton];
    
    //修饰分割线
    UIView *lineVertical = [[UIView alloc] init];
    
    lineVertical.backgroundColor = RGB(238, 238, 238);
    
    [stackView addSubview:lineVertical];
    
    [lineVertical mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(stackView.mas_centerX);
        make.top.equalTo(stackView.mas_top);
        make.width.mas_equalTo(0.5);
        make.height.mas_equalTo(50);
    }];
}

#pragma mark    - - - Action - - -

//直接申请
- (void)directApplication:(UIButton *)sender
{
    if (self.delegate && [_delegate respondsToSelector:@selector(submitUserInfoViewSelectIndex:)]) {
        [self.delegate submitUserInfoViewSelectIndex:1];
    }
}

//马上申请
- (void)atOnceTimeApplication:(UIButton *)sender
{
    if (self.delegate && [_delegate respondsToSelector:@selector(submitUserInfoViewSelectIndex:)]) {
        [self.delegate submitUserInfoViewSelectIndex:2];
    }
}

//删除弹窗显示
- (void)deleteAlertAction:(UIButton *)sender
{
    if (self.delegate && [_delegate respondsToSelector:@selector(submitUserInfoViewSelectIndex:)]) {
        [self.delegate submitUserInfoViewSelectIndex:3];
    }
}


#pragma mark    - - - 懒加载 - - -

- (UILabel *)titleOne
{
    if (!_titleOne) {
        self.titleOne = [[UILabel alloc] init];
        
        self.titleOne.textAlignment = NSTextAlignmentLeft;
        
        self.titleOne.attributedText = [self setLabelWithTitle:@"1.个人主页多上传一些照片 "];
    }
    
    return _titleOne;
}

- (UILabel *)titleTwo
{
    if (!_titleTwo) {
        self.titleTwo = [[UILabel alloc] init];
        
        self.titleTwo.textAlignment = NSTextAlignmentLeft;
        
        self.titleTwo.attributedText = [self setLabelWithTitle:@"2.挑选高质量照片作为头"];
    }
    
    return _titleTwo;
}

- (UILabel *)titleThree
{
    if (!_titleThree) {
        self.titleThree = [[UILabel alloc] init];
        
        self.titleThree.textAlignment = NSTextAlignmentLeft;
        
        self.titleThree.attributedText = [self setLabelWithTitle:@"3.多上传个人短视频作品"];
    }
    
    return _titleThree;
}


#pragma mark    - - - Help Tools - - -

- (NSMutableAttributedString *)setLabelWithTitle:(NSString *)title
{
    NSDictionary *dic = @{NSKernAttributeName:@1,
                          NSForegroundColorAttributeName:RGB(102, 102, 102),
                          NSFontAttributeName:[UIFont fontWithName:kFontNamePFRegular size:kScale(15)]
                          };
    
    NSMutableAttributedString *attribute = [[NSMutableAttributedString alloc] initWithString:title attributes:dic];
    
    return attribute;
}


@end
